package com.project;

public class ThreadTest {
    public static void main(String[] args) {
        Thread1 t = new Thread1();
        t.start();

        Thread2 t2 = new Thread2();
        //创建线程对象时，传入Runnable实现类对象
        //线程启动后，会执行Runnable实现类对象run（）
        Thread th = new Thread(t2);
        th.start();

        for(int i=0;i<10;i++){
            System.out.println(i);
            try {
                //线程的休眠，休眠500毫秒，休眠结束后，继续执行当前线程
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

class Thread1 extends Thread{
    @Override
    public void run(){
        for (int i=10;i<20;i++){
            System.out.println(i);
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

class Thread2 implements Runnable{

    @Override
    public void run() {
        for (int i=20;i<30;i++){
            System.out.println(i);
            try {
                Thread.sleep(20);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
